home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / gray image 2.1 / mymenv.h < prev    next >
Text File  |  1995-06-13  |  4KB  |  109 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. //************************************************************************
  3. //
  4. //                      A standard Macintosh environment
  5. //                        I am accustomed to
  6. //
  7. // $Id: myenv.h,v 1.3 1995/02/08 17:23:51 oleg Exp oleg $
  8.  
  9. #pragma once
  10. #ifndef _mymenv_h
  11. #define _mymenv_h 1
  12.  
  13.  
  14.                                 /* Alert the user and that we're about */
  15.                                 /* to die                              */
  16. volatile void _die(
  17.         const char * message,           /* Message to be printed        */
  18.         ...                             /* Additional args to printf    */
  19.            );
  20.  
  21.                                 /* Alert the user            */
  22. void alert(
  23.         const char * text,              /* Message to be printed        */
  24.         ...                             /* Additional args to printf    */
  25.            );
  26.  
  27.  
  28.  
  29. //------------------------------------------------------------------------
  30. //                  Macintosh convenience functions
  31.  
  32.  
  33.                                     // Pascal String, this is just a type conversion
  34. class Pstr
  35. {
  36.     Str255 pas_string;
  37. public:
  38.     Pstr(const char * c_str);
  39.     operator unsigned char const * (void) { return pas_string; }
  40. };
  41.  
  42. //------------------------------------------------------------------------
  43. //                  Patches to the standard environment
  44.  
  45. #ifndef _myenv_h
  46.                                 // Like strncpy(), but ALWAYS terminates
  47.                                 // the destination string
  48. char * xstrncpy(char * dest, const char * src, const int len);
  49. #endif
  50.  
  51. //------------------------------------------------------------------------
  52. //                        Verify the assertion
  53.  
  54. #ifndef assert
  55. #define assert(ex) \
  56.         (void)((ex) ? 1 : \
  57.               (_die("Failed assertion " #ex " at line %ld of `%s'.", \
  58.                __LINE__, __FILE__), 0))
  59. #endif
  60. #ifndef assertval
  61. #define assertval(ex) assert(ex)
  62. #endif
  63.  
  64. #ifndef assure
  65. #define assure(expr,message)                \
  66.     if    (expr) ;                \
  67.     else _die("%s at line %ld of '%s'.",message,__LINE__, __FILE__);
  68. #endif
  69.                                         // Execute the function 'ex' and make sure
  70.                                         // it return noErr
  71. #define do_well(ex) \
  72.         { OSErr err = (ex); if( err != noErr ) \
  73.               _die("Failed call " #ex " with error %ld at line %ld of `%s'.", \
  74.                err, __LINE__, __FILE__); }
  75.  
  76. //------------------------------------------------------------------------
  77. //                             Notification posting
  78. // The set of functions below let a (backgound) application to post 
  79. // synchronous or asynchronous notification messages to the user.
  80. // Synchronous posting means that function does not return until the
  81. // notification message is displayed and the user dismisses it.
  82. // In asynchronous mode, the posting function returns as soon as the
  83. // message is queued into the notification queue (but not yet displayed!).
  84. // 
  85.  
  86. void notify_and_wait(const char * messg,...);
  87. void notify(const char * messg,...);
  88.  
  89. //------------------------------------------------------------------------
  90. //                            Sound playing on errors
  91.  
  92. void set_error_sound(Str255 sound_name);
  93.  
  94. //------------------------------------------------------------------------
  95. //                            Macintosh System Utilities
  96.  
  97.  
  98.  
  99. void Initialize_MAC(void);
  100. void sleep(const int nticks);            // Generous suspension for a specified no. of ticks
  101.  
  102.                                         // Launch an application and have it handle the
  103.                                         // specified file, as if the file were
  104.                                         // "double-clicked"
  105. void open_selection(const char * full_path_name);
  106.  
  107.  
  108. #endif
  109.